package com.cndw.kungfu.model.activity.holiday;

import java.util.HashMap;
import java.util.Map;

import com.cndw.kungfu.config.ConstantsDayIntKey;
import com.cndw.kungfu.domain.Player;
import com.cndw.kungfu.domain.TaskMode;
import com.cndw.kungfu.ext.LogUtil;

public class ActTaskConfig {
	
	/**
	 * 日常任务
	 */
	private static final int sub_dayly = 101;
	/**
	 * 帮派任务
	 */
	private static final int sub_union = 102;
	/**
	 * 声望任务
	 */
	private static final int sub_per = 103;
	/**
	 * 祭拜财神
	 */
	private static final int sub_pray = 104;
	/**
	 * 摘取上古神树
	 */
	private static final int sub_treeGain = 105;
	/**
	 * 修为值
	 */
	private static final int sub_dailyScore = 106;
	/**
	 * 帮派神树浇水
	 */
	private static final int sub_uTreeWarter = 107;
	/**
	 * 击杀大于或等于人物等级的野外怪物100只
	 */
	private static final int sub_monsterKill = 108;
	/**
	 * 施舍神丐
	 */
	private static final int sub_lottery = 109;
	/**
	 * 加速神树
	 */
	private static final int sub_treeFast = 110;
	/**
	 * 开启酒宴
	 */
	private static final int sub_wine = 111;
	/**
	 * 进行徒弟成长白金洗点
	 */
	private static final int sub_disWash1 = 112;
	/**
	 * 进行徒弟成长至尊洗点
	 */
	private static final int sub_disWash2 = 113;
	
	
	/**
	 * 西施活动目标一
	 */
	private static final int task1 = 1;
	/**
	 * 西施活动目标二
	 */
	private static final int task2 = 2;
	/**
	 * 西施活动目标三
	 */
	private static final int task3 = 3;
	/**
	 * 西施活动目标四
	 */
	private static final int task4 = 4;
	/**
	 * 西施活动目标五
	 */
	private static final int task5 = 5;
	
	
	private static Map<Integer, int[][]> taskMap = new HashMap<Integer, int[][]>();
	
	static {
		taskMap.put(task1, new int[][]{{sub_dayly, 1}, {sub_union, 1}, {sub_per, 1}});
		taskMap.put(task2, new int[][]{{sub_pray, 10}, {sub_treeGain, 8}, {sub_dailyScore, 65}, {sub_uTreeWarter, 1}});
		taskMap.put(task3, new int[][]{{sub_monsterKill, 100}, {sub_lottery, 10}, {sub_pray, 30}, {sub_dailyScore, 80}, {sub_treeFast, 10}});
		taskMap.put(task4, new int[][]{{sub_wine, 3}, {sub_pray, 50}, {sub_lottery, 20}});
		taskMap.put(task5, new int[][]{{sub_disWash1, 10}, {sub_disWash2, 5}, {sub_lottery, 30}});
	}
	
	public static int getSubState(Player player, int subId) {
		
		int state = 0;
		try {
			switch (subId) {
			case sub_dayly:
				state = player.getDataInfo().getEveryDay().getTaskTimes(TaskMode.typeDaily);
				break;
			case sub_union:
				state = player.getDataInfo().getEveryDay().getTaskTimes(TaskMode.typeUnionCycle);
				break;
			case sub_per:
				state = player.getDataInfo().getEveryDay().getTaskTimes(TaskMode.typePrestige);
				break;
			case sub_pray:
				state = player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.prayCounts);
				break;
			case sub_treeGain:
				state = player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.fruit);
				break;
			case sub_dailyScore:
				state = player.getDataInfo().getEveryDay().getDailyScore();
				break;
			case sub_uTreeWarter:
				state = player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.utw);
				break;
			case sub_monsterKill:
				state = player.getDataInfo().getEveryDay().getBattleNum();
				break;
			case sub_lottery:
				state = player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.tbl);
				break;
			case sub_treeFast:
				state = player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.tft);
				break;
			case sub_wine:
				state = player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.winne);
				break;
			case sub_disWash1:
				state = player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.dwp1);
				break;
			case sub_disWash2:
				state = player.getDataInfo().getEveryDay().intDataGet(ConstantsDayIntKey.dwp2);
				break;
			default:
				break;
			}
		} catch (Exception e) {
			e.printStackTrace();
			LogUtil.getMain().error("ActTaskConfig subTask Err " + subId);
		}
		return state;
	}
	
	
	public static int[][] getAllState(Player player) {
		int[][] stateArr = new int[taskMap.size()][];
		int i = 0;
		for (Integer tId : taskMap.keySet()) {
			stateArr[i] = getTaskState(player, tId);
			i++;
		}
		return stateArr;
	}
	
	public static int[] getTaskState(Player player, int taskId) {
		if (!isContain(taskId)) {
			return null;
		}
		try {
			int[][] task = taskMap.get(taskId);
			int[] stateArr = new int[task.length + 1];
			int finishCount = 0;
			for (int i = 0; i < task.length; i++) {
				stateArr[i + 1] = getSubState(player, task[i][0]);
				finishCount += stateArr[i + 1] >= task[i][1] ? 1 : 0;
			}
			if (finishCount >= task.length) {
				stateArr[0] = 1;
			}
			return stateArr;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public static Map<Integer, int[][]> getTaskMap() {
		return taskMap;
	}
	
	public static boolean isContain(int taskId) {
		return taskMap.containsKey(taskId);
	}
	
}
